package com.f.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.f.Dao.CommodityDao;
import com.f.bean.Commodity;

/**
 * Servlet implementation class UpdateServlet
 */
@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Commodity comm = new Commodity();
		int upId = Integer.parseInt(request.getParameter("upId"));
		comm.setId(Integer.parseInt(request.getParameter("id")));
		comm.setClass_id(Integer.parseInt(request.getParameter("class_id")));
		comm.setTitle(request.getParameter("title"));
		comm.setPrice(Float.parseFloat(request.getParameter("price")));
		comm.setPlace(request.getParameter("place"));
		comm.setAlcohol(request.getParameter("alcohol"));
//		if(request.getParameter("content") == null || request.getParameter("content").trim().equals("")) {
//			comm.setContent(request.getParameter("content"));
//		}
		comm.setContent(request.getParameter("content"));
		try {
			new CommodityDao().update(upId,comm);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.sendRedirect(request.getHeader("Referer"));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
